package cn.schoolwow.util.domain.query.instance;

import cn.schoolwow.quickflow.QuickFlow;
import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.util.module.query.instance.service.GetInstanceFieldValueFlow;
import cn.schoolwow.util.module.query.instance.service.GetInstanceFieldsValueFlow;

import java.util.Collection;


public class QueryInstanceResponse {
    private QuickFlow quickFlow;

    public QueryInstanceResponse(QuickFlow quickFlow) {
        this.quickFlow = quickFlow;
    }

    /**获取指定字段值*/
    public Object getSingleFieldValue(String fieldName){
        FlowContext flowContext = quickFlow.startFlow(new GetInstanceFieldValueFlow())
                .putCurrentCompositeFlowData("fieldName", fieldName)
                .execute();
        Object fieldValue = flowContext.getData("fieldValue");
        return fieldValue;
    }

    /**获取指定字段值*/
    public <T> T getSingleFieldValue(String fieldName, Class<T> classType){
        FlowContext flowContext = quickFlow.startFlow(new GetInstanceFieldValueFlow())
                .putCurrentCompositeFlowData("fieldName", fieldName)
                .execute();
        T fieldValue = (T) flowContext.getData("fieldValue");
        return fieldValue;
    }

    /**获取指定多个字段值*/
    public Object getMultipleFieldValue(String... fieldNames){
        FlowContext flowContext = quickFlow.startFlow(new GetInstanceFieldsValueFlow())
                .putCurrentCompositeFlowData("fieldNames", fieldNames)
                .execute();
        Object fieldValue = flowContext.getData("fieldValue");
        return fieldValue;
    }

    /**获取指定多个字段值*/
    public Object getMultipleFieldValue(Collection<String> fieldNames){
        FlowContext flowContext = quickFlow.startFlow(new GetInstanceFieldsValueFlow())
                .putCurrentCompositeFlowData("fieldNames", fieldNames.toArray(new String[0]))
                .execute();
        Object fieldValue = flowContext.getData("fieldValue");
        return fieldValue;
    }

}
